package com.mutual.healthInfo.service.impl;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.mutual.commom.util.SystemUtil;
import com.mutual.healthInfo.dao.HealthInfoDao;
import com.mutual.healthInfo.pojo.HealthInfo;
import com.mutual.healthInfo.service.HealthInfoService;


@Service
public class HealthInfoServiceImpl implements HealthInfoService {

	@Resource
	private HealthInfoDao healthInfoDao;
	
	@Override
	public void insert(HealthInfo entity) {
		entity.setCreateDate(new Date());
		entity.setUpdateDate(new Date());
		healthInfoDao.insertSelective(entity);
	}

	@Override
	public void updateByPrimaryKey(HealthInfo entity) {
		if(entity.getClickCount()==null){
			entity.setUpdateDate(new Date());
		}
		healthInfoDao.updateByPrimaryKeySelective(entity);
	}

	@Override
	public HealthInfo selectByPrimaryKey(Serializable entityid) {
		return healthInfoDao.selectByPrimaryKey(entityid);
	}

	@Override
	public int selectHealthInfoCount(Map<String, Object> param) {
		return healthInfoDao.selectTotalCount(param);
	}

	@Override
	public List<HealthInfo> selectHealthInfoList(Map<String, Object> param) {
		if(param.containsKey("page")){
			int pageNo=SystemUtil.getPageNo(param.get("page"));
			int pageSize=Integer.parseInt(param.get("limit").toString());
			param.put("startNo", (pageNo-1)*pageSize);
			param.put("pageSize", pageSize);
		}
		return healthInfoDao.selectObjectList(param);
	}

	@Override
	public void deleteHealthInfo(int id) {
		healthInfoDao.deleteByPrimaryKey(id);
	}
}
